﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_中const和readonly关键字以及readonly修饰的变量怎样修改
{
    internal class TestConst
    {
        public const int constNum = 0;
        public readonly int readonlyNum;
        public static readonly int staticReadonlyNum;
        public readonly List<int> listNums = new List<int>();

        public TestConst()
        {
            //constNum = 1;//构造方法里面不能对常量进行调整

            readonlyNum = 1; //只读属性可以

            //staticReadonlyNum = 2;//静态的只读属性不可以

            listNums.Add(1);//只读集合可以
        }

        static TestConst() //静态构造方法
        {
            staticReadonlyNum = 2;//静态的只读属性可以
        }
    }
}
